home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / blank / bserver_v14.lha / BServer_v1.4 / Sources.lha / Sources / clients / Poly.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-23  |  7.8 KB  |  274 lines

  1. ;/*
  2. sc RESOPT IGNORE=73 DATA=NEAR NMINC UCHAR CONSTLIB STREQ STRMERGE NOSTKCHK NOSTDIO OPTIMIZE OPTSIZE Poly.c
  3. Slink from LIB:catch.o Poly.o to //Clients/Poly LIB LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD NOICONS STRIPDEBUG
  4. delete Poly.o
  5. quit
  6.  
  7.  Poly 1.0  (Client for BServer)
  8.  
  9.  Copyright © 1995 by Stefano Reksten of 3AM - The Three Amigos!!!
  10.  All rights reserved.
  11.  
  12. */
  13.  
  14. #include <exec/types.h>
  15. #include <exec/memory.h>
  16. #include <graphics/gfxbase.h>
  17.  
  18. #include <proto/exec.h>
  19. #include <proto/intuition.h>
  20. #include <proto/graphics.h>
  21. #include <proto/layers.h>
  22. #include <clib/alib_protos.h>
  23. #include <string.h>
  24. #include <time.h>
  25. #include <math.h>
  26.  
  27. #include "/include/client.h"
  28.  
  29. char *ver = "$VER: Poly 1.0 "__AMIGADATE__;
  30.  
  31. struct IntuitionBase *IntuitionBase;
  32. struct GfxBase *GfxBase;
  33. struct Library *LayersBase;
  34.  
  35. struct DisplayIDInformation *dinfo;
  36.  
  37. struct Screen *scr;
  38.  
  39. #define MOREEDGES    6
  40. #define MINEDGES    6
  41. #define SCRDEPTH    4
  42. #define NUMCOLORS    16
  43.  
  44. extern ULONG RangeSeed;
  45. UWORD swidth, sheight, maxw, maxh;
  46. UBYTE brightness;
  47.  
  48. /* Get a random color in r g b... */
  49.  
  50. UBYTE r, g, b;
  51.  
  52. UBYTE RandomColor( UBYTE rng )
  53. {
  54. if ( CheckAA() )
  55.     return( (UBYTE)((RangeRand(rng<<4)+256-(rng<<4))*brightness/100) );
  56. else
  57.     return( (UBYTE)((RangeRand(rng)+16-rng)*brightness/100) );
  58. }
  59.  
  60. void SetRGBTriplet( void )
  61. {
  62. r = RandomColor(16);
  63. g = RandomColor(16);
  64. b = RandomColor(16);
  65. }
  66.  
  67. signed char costable[450] = {
  68.   127,   127,   127,   127,   127,   127,   127,   127,   127,   127, 
  69.   126,   126,   126,   125,   125,   124,   124,   123,   122,   122, 
  70.   121,   120,   119,   119,   118,   117,   116,   115,   114,   113, 
  71.   112,   111,   110,   109,   107,   106,   105,   104,   102,   101, 
  72.    99,    98,    97,    95,    94,    92,    91,    89,    87,    86, 
  73.    84,    82,    81,    79,    77,    75,    73,    72,    70,    68, 
  74.    66,    64,    62,    60,    58,    56,    54,    52,    50,    48, 
  75.    46,    44,    42,    40,    37,    35,    33,    31,    29,    27, 
  76.    24,    22,    20,    18,    16,    13,    11,     9,     7,     4, 
  77.     2,     0,    -2,    -4,    -7,    -9,   -11,   -13,   -16,   -18, 
  78.   -20,   -22,   -24,   -27,   -29,   -31,   -33,   -35,   -37,   -40, 
  79.   -42,   -44,   -46,   -48,   -50,   -52,   -54,   -56,   -58,   -60, 
  80.   -62,   -64,   -66,   -68,   -70,   -72,   -73,   -75,   -77,   -79, 
  81.   -81,   -82,   -84,   -86,   -87,   -89,   -91,   -92,   -94,   -95, 
  82.   -97,   -98,   -99,  -101,  -102,  -104,  -105,  -106,  -107,  -109, 
  83.  -110,  -111,  -112,  -113,  -114,  -115,  -116,  -117,  -118,  -119, 
  84.  -119,  -120,  -121,  -122,  -122,  -123,  -124,  -124,  -125,  -125, 
  85.  -126,  -126,  -126,  -127,  -127,  -127,  -128,  -128,  -128,  -128, 
  86.  -128,  -128,  -128,  -128,  -128,  -128,  -128,  -127,  -127,  -127, 
  87.  -126,  -126,  -126,  -125,  -125,  -124,  -124,  -123,  -122,  -122, 
  88.  -121,  -120,  -119,  -119,  -118,  -117,  -116,  -115,  -114,  -113, 
  89.  -112,  -111,  -110,  -109,  -107,  -106,  -105,  -104,  -102,  -101, 
  90.   -99,   -98,   -97,   -95,   -94,   -92,   -91,   -89,   -87,   -86, 
  91.   -84,   -82,   -81,   -79,   -77,   -75,   -73,   -72,   -70,   -68, 
  92.   -66,   -64,   -62,   -60,   -58,   -56,   -54,   -52,   -50,   -48, 
  93.   -46,   -44,   -42,   -40,   -37,   -35,   -33,   -31,   -29,   -27, 
  94.   -24,   -22,   -20,   -18,   -16,   -13,   -11,    -9,    -7,    -4, 
  95.    -2,    -0,     2,     4,     7,     9,    11,    13,    16,    18, 
  96.    20,    22,    24,    27,    29,    31,    33,    35,    37,    40, 
  97.    42,    44,    46,    48,    50,    52,    54,    56,    58,    60, 
  98.    62,    64,    66,    68,    70,    72,    73,    75,    77,    79, 
  99.    81,    82,    84,    86,    87,    89,    91,    92,    94,    95, 
  100.    97,    98,    99,   101,   102,   104,   105,   106,   107,   109, 
  101.   110,   111,   112,   113,   114,   115,   116,   117,   118,   119, 
  102.   119,   120,   121,   122,   122,   123,   124,   124,   125,   125, 
  103.   126,   126,   126,   127,   127,   127,   127,   127,   127,   127, 
  104.   127,   127,   127,   127,   127,   127,   127,   127,   127,   127, 
  105.   126,   126,   126,   125,   125,   124,   124,   123,   122,   122, 
  106.   121,   120,   119,   119,   118,   117,   116,   115,   114,   113, 
  107.   112,   111,   110,   109,   107,   106,   105,   104,   102,   101, 
  108.    99,    98,    97,    95,    94,    92,    91,    89,    87,    86, 
  109.    84,    82,    81,    79,    77,    75,    73,    72,    70,    68, 
  110.    66,    64,    62,    60,    58,    56,    54,    52,    50,    48, 
  111.    46,    44,    42,    40,    37,    35,    33,    31,    29,    27, 
  112.    24,    22,    20,    18,    16,    13,    11,     9,     7,     4 };
  113.  
  114. UWORD coord[MOREEDGES + MINEDGES][2];
  115. UBYTE colors[NUMCOLORS][3];
  116. UWORD max_radius;
  117. UWORD min_radius;
  118.  
  119.  
  120. void DrawAPolygon( UBYTE color )
  121. {
  122. UWORD x, y;
  123. UBYTE n, m, edges;
  124. UBYTE radius;
  125. register struct RastPort *rp = &scr->RastPort;
  126.  
  127. radius = RangeRand( max_radius - min_radius ) + min_radius;
  128.  
  129. x = RangeRand( swidth - 2 * radius ) + radius;
  130. y = RangeRand( sheight - 2 * radius ) + radius;
  131.  
  132. edges = RangeRand( MOREEDGES ) + MINEDGES;
  133.  
  134. for ( n = 0; n < edges; n++ )
  135.     {
  136.     coord[n][0] = x + radius * costable[ (360 * n) / edges ] / 128;
  137.     coord[n][1] = y + radius * costable[ 90 + ((360 * n) / edges) ] / 128;
  138.     }
  139.  
  140. SetRGBTriplet();
  141. if ( CheckAA() )
  142.     SetRGB32( &scr->ViewPort, color, r<<24, g<<24, b<<24 );
  143. else
  144.     SetRGB4( &scr->ViewPort, color, r, g, b );
  145. colors[color][0] = r;
  146. colors[color][1] = g;
  147. colors[color][2] = b;
  148.  
  149. SetAPen( rp, color );
  150. for ( n = 0; n < edges; n++ )
  151.     for ( m = n; m < edges; m++ )
  152.         {
  153.         Move( rp, coord[n][0], coord[n][1] );
  154.         Draw( rp, coord[m][0], coord[m][1] );
  155.         }
  156. }
  157.  
  158.  
  159. #define POLY_ACTION_DRAWING    1
  160. #define POLY_ACTION_CLEARING 2
  161.  
  162. void Blank( void )
  163. {
  164. UBYTE whichColor, poly_action, fade_delay;
  165. BOOL faded, aa = CheckAA();
  166. ULONG displayID;
  167. struct Rectangle *rect;
  168.  
  169. rect = GETTXTOSCANRECT(dinfo);
  170.  
  171. swidth = RECTANGLEWIDTH(rect);
  172. sheight = RECTANGLEHEIGHT(rect);
  173. displayID = DISPLAYID(dinfo);
  174. brightness = GETBRIGHTNESS(dinfo);
  175.  
  176. if ( !CheckAA() )
  177.     {
  178.     if ( displayID & SUPERHIRES )
  179.         {
  180.         displayID &= ~SUPERHIRES;
  181.         displayID |= HIRES;
  182.         }
  183.     }
  184.  
  185. if ( (scr = OpenScreenTags( NULL,
  186.         SA_Width, swidth,
  187.         SA_Height, sheight,
  188.         SA_Depth, SCRDEPTH,
  189.         SA_Type, CUSTOMSCREEN,
  190.         SA_Quiet, TRUE,
  191.         SA_DisplayID, displayID,
  192.         SA_Overscan, OSCAN_TEXT,
  193.         TAG_END ) ) )
  194.     {
  195.     SpritesOff();
  196.     SetRGB4( &scr->ViewPort, 0, 0, 0, 0 );
  197.  
  198.     max_radius = swidth > sheight ? (sheight >> 2) : (swidth >> 2);
  199.     min_radius = max_radius >> 2;
  200.     poly_action = POLY_ACTION_DRAWING;
  201.     whichColor = 1;
  202.     fade_delay = 0;
  203.  
  204.     while( STILL_BLANKING )
  205.         {
  206.         if ( poly_action == POLY_ACTION_DRAWING )
  207.             {
  208.             DrawAPolygon( whichColor );
  209.             if ( ++whichColor >= NUMCOLORS )
  210.                 poly_action = POLY_ACTION_CLEARING;
  211.             }
  212.         else
  213.             {
  214.             faded = TRUE;
  215.             WaitTOF();
  216.             if ( ++fade_delay == 16 || aa )
  217.                 {
  218.                 fade_delay = 0;
  219.                 for ( whichColor = 1; whichColor < NUMCOLORS; whichColor++ )
  220.                     {
  221.                     if ( r = colors[whichColor][0] ) colors[whichColor][0]--;
  222.                     if ( g = colors[whichColor][1] ) colors[whichColor][1]--;
  223.                     if ( b = colors[whichColor][2] ) colors[whichColor][2]--;
  224.  
  225.                     if ( r || g || b )
  226.                         {
  227.                         if ( aa )
  228.                             SetRGB32( &scr->ViewPort, whichColor, r<<24, g<<24, b<<24 );
  229.                         else
  230.                             SetRGB4( &scr->ViewPort, whichColor, r, g, b );
  231.                         faded = FALSE;
  232.                         }
  233.                     }
  234.  
  235.                 if ( faded )
  236.                     {
  237.                     SetRast( &scr->RastPort, 0 );
  238.                     poly_action = POLY_ACTION_DRAWING;
  239.                     whichColor = 1;
  240.                     }
  241.                 }
  242.             }
  243.         }
  244.  
  245.     SpritesOn();
  246.     CloseScreen( scr );
  247.     }
  248. else
  249.     SendClientMsg( ACTION_FAILED );
  250. }
  251.  
  252.  
  253. void __main( char *line )
  254. {
  255. if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 37L ) )
  256.     {
  257.     if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 37L ) )
  258.         {
  259.         if ( LayersBase = OpenLibrary( "layers.library", 37L ) )
  260.             {
  261.             if ( dinfo = OpenCommunication() )
  262.                 {
  263.                 RangeSeed = time( NULL );
  264.                 Blank();
  265.                 CloseCommunication( dinfo );
  266.                 }
  267.             CloseLibrary( LayersBase );
  268.             }
  269.         CloseLibrary( (struct Library *)GfxBase );
  270.         }
  271.     CloseLibrary( (struct Library *)IntuitionBase );
  272.     }
  273. }
  274.